# Contributor: Sam Whited <sam@samwhited.com>
# Maintainer: Sam Whited <sam@samwhited.com>
pkgname=lua-unbound
_rockname=luaunbound
pkgver=1.0.0
pkgrel=0
pkgdesc="Lua bindings to libunbound"
url="https://www.zash.se/luaunbound.html"
arch="all"
license="MIT"
makedepends="unbound-dev"
source="https://code.zash.se/dl/$_rockname/$_rockname-$pkgver.tar.gz"
builddir="$srcdir/$_rockname-$pkgver"

_luaversions="5.1 5.2 5.3 5.4"
for _v in $_luaversions; do
	makedepends="$makedepends lua$_v-dev"
	subpackages="$subpackages lua$_v-${pkgname#lua-}:_subpackage"
done

prepare() {
	default_prepare

	local lver; for lver in $_luaversions; do
		msg "Preparing build dir for Lua $lver..."

		cp -r "$builddir" "$builddir"-$lver
	done
}

build() {
	local lver; for lver in $_luaversions; do
		msg "Building for Lua $lver..."
		cd "$builddir"-$lver

		make LD=cc LUA_PC=lua$lver
	done
}

check() {
	# no actual tests, just try import
	local lver; for lver in $_luaversions; do
		msg "Testing for Lua $lver..."
		cd "$builddir"-$lver

		lua$lver -e 'require("lunbound"); print("pass")'
	done
}

package() {
	local lver; for lver in $_luaversions; do
		msg "Installing for Lua $lver..."

		install -Dm755 "$builddir"-$lver/lunbound.so \
			-t "$pkgdir"/usr/lib/lua/$lver
	done
}

_subpackage() {
	local lver="${subpkgname:3:3}"
	pkgdesc="$pkgdesc (for Lua $lver)"
	install_if="$pkgname=$pkgver-r$pkgrel lua$lver"

	amove usr/lib/lua/$lver
}

sha512sums="
9fab77481e7c84409d9ceb79156d06cb9ac2b2d7df53349e0f1b6c118022c9b1c22481e9413efedda41cc9acb1640d3d30cc4e0f9b7ed7fd6ed2511192a69d3c  luaunbound-1.0.0.tar.gz
"
